package com.tanchengjin.admin.modules.blog.config.resttemplate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {
    @Autowired
    private RestTemplateBuilder restTemplateBuilder;

    @Bean
    public RestTemplate restTemplate() {
//        return restTemplateBuilder.setConnectTimeout().build();
        return new RestTemplate(clientHttpRequestFactory());
    }

    /**
     * 配置RestTemplate连接工厂
     */
    @Bean
    public ClientHttpRequestFactory clientHttpRequestFactory() {
        SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
        //毫秒
        simpleClientHttpRequestFactory.setConnectTimeout(5000);
        //毫秒
        simpleClientHttpRequestFactory.setReadTimeout(500);
        return simpleClientHttpRequestFactory;
    }
}
